import {Component, Input, OnInit} from '@angular/core';
import {Award} from "../svrs/domain";
import {AwardService} from "../svrs/award.service";
import {ActivatedRoute} from "@angular/router";
import {DialogConfig, DialogService, ToastService} from "ngx-weui";

@Component({
  selector: 'app-aaa',
  templateUrl: './aaa.component.html',
  styleUrls: ['./aaa.component.css']
})
export class AaaComponent implements OnInit {
  awards:Award[];
  index;
  indexa;
  i;
  ii=0;
  www;
  wwww;
  aaa=0;
  eee;
  z;
  x;
  c;
  http1;
  http2;
  http3;
  w1;
  w2;
  w3;
  started=0;
  constructor(private svr:AwardService,private aRouter:ActivatedRoute,
              private  svr1:ToastService,private srv:DialogService
  ) {
    aRouter.params.subscribe(pars=>{
      if(pars && pars.awardId1){
        this.index=parseInt(pars.awardId1)-1;
      }
    })
    aRouter.params.subscribe(pars=>{
      if(pars && pars.prizeId){
        this.indexa=parseInt(pars.prizeId);
      }
    })
    this.svr.getawards().subscribe(
      (data)=>{
        this.awards=data;

      }
    )

  }

  ngOnInit() {
  }

d() {
  if (this.aaa != 0) {
    this.aaa =this.aaa==1?2:1
  }
  else {
    this.i = 0;
    this.www = 10 + Math.floor(Math.random() * 10);
    let dd = setInterval(() => {
      if(this.aaa==2) return;
      this.i++;
      this.eee = this.i % this.awards[this.index].prizes.length;
      if (this.i == this.www) {
        clearInterval(dd);

      }
    }, 300);
this.aaa=1;
  }
}
g(){
  this.wwww = 10 + Math.floor(Math.random() * 10);
    this.ii=0;
let tt=setInterval(()=>{
this.ii++;
this.z=this.ii % this.awards[this.index].prizes.length;

  this.x= this.ii % this.awards[this.index].prizes.length;
  this.c=this.ii % this.awards[this.index].prizes.length;
  if (this.ii == this.wwww) {
    clearInterval(tt);

  }
},300)

}
h(){
  if(this.started==0) {
    let w1 = "/assets/img/359723340.jpg";
    // let w1="http://www.zm-it.cn/images/"+this.awards[this.index].pics[0];
    let w2 = "/assets/img/1364218760.jpg";
    let w3 = "/assets/img/1732529504.jpg";
    this.wwww = 9 + Math.floor(Math.random() * 10);
    let hh = setInterval(() => {
      this.ii++;
      this.www = this.ii % 3;
      if (this.www == 0) {
        this.http1 = w1;
        let time1 = setTimeout(() => {
          this.http2 = w1;
        }, 500)
        let time2 = setTimeout(() => {
          this.http3 = w1;
        }, 1000)
      } else {
        if (this.www == 1) {
          this.http1 = w2;
          let time1 = setTimeout(() => {
            this.http2 = w2;
          }, 500)
          let time2 = setTimeout(() => {
            this.http3 = w2;
          }, 1000)

        } else {
          if (this.www == 2) {
            this.http1 = w3;
            let time1 = setTimeout(() => {
              this.http2 = w3;
            }, 500)
            let time2 = setTimeout(() => {
              this.http3 = w3;
            }, 1000)
          }
        }

      }
      if (this.ii == this.wwww) {
        clearInterval(hh);
        let time3 = setTimeout(() => {
          this.svr1.success("已中奖");
        }, 1000)

      }

    }, 500)
    this.ii = 0;
    this.started = 1;
  }
}
}
